package com.ndp.fb.rdb.db.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ndp.fb.rdb.api.RuleSettingsRdbService;
import com.ndp.fb.rdb.db.DaoTemplate;
import com.ndp.fb.rdb.db.impl.mapper.DefaultRowMapper;
import com.ndp.fb.rdb.model.RuleSettings;

import java.util.List;

/**
 * Created by hunk.qin on 2015/9/14.
 */
@Service
public class RuleSettingsRdbServiceImpl extends DaoTemplate implements RuleSettingsRdbService {

    @Override
    public List<RuleSettings> getRuleSettingsByUserId(String userId) {
        String selSql = "SELECT * FROM rule_settings where user_id = ?";
        return getJdbcTemplate().query(selSql, new Object[]{userId}, DefaultRowMapper.autoRowMapper(RuleSettings.class));
    }

    @Override
    public void saveSetting(List<RuleSettings> userSettings) {
        batchSaveResultId(userSettings);
    }

    @Override
    public void deleteByUserId(String userid) {
        String selSql = "DELETE FROM rule_settings where user_id ='"+userid+"'";
        getJdbcTemplate().execute(selSql);

    }
}
